var ns, trycount = 0;
var app = new Vue({
    el: '#app',
    data: {
        footers: [{
            title: '任务',
            name: 'home_allTasks_list',
            is_active: false,
            normal: '../image/index/menu_icon_2.png',
            selected: '../image/index/menu_icon_2_action.png',
            categoryid: 0,
            type: 0,
            count: 0
        }, {
            title: '工作',
            name: 'index_frm',
            is_active: true,
            normal: '../image/index/menu_icon_1.png',
            selected: '../image/index/menu_icon_1_active.png',
            categoryid: 0,
            type: 0,
            count: 0
        }]
    },
    methods: {
        get_read_state: function() {
            var that = this;
            var options = {};
            options.action = "gettotalundreadpushmsgcount";
            ns.post(options, function(succeed, data, err) {
                if (succeed) {
                    that.footers[1].count = data.count;
                } else {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        },
        open_menu: function(item) {
            var that = this;
            for (var i = 0; i < that.footers.length; i++) {
                that.footers[i].is_active = false;
            }
            item.is_active = true;
            var frameH = api.winHeight - 50;

            ns.openFrame(item.name, {
                servicetype: item.type
            }, {
                rect: {
                    x: 0,
                    y: 0,
                    w: 'auto',
                    h: frameH
                }
            });
            //刷新首页-任务列表数量
            if (item.title == '任务') {
                api.sendEvent({
                    name: 'home-refresh'
                })
            }
            if (item.name == 'customerservice_win') {
                api.sendEvent({
                    name: 'doopenservicewin',
                });
            }
            if (item.name == 'home_news_win') {
                api.sendEvent({
                    name: 'doopenhomenewswin',
                });
            }
        },
        set_status_bar: function() {
            var that = this;
            api.setStatusBarStyle({
                style: 'dark',
                color: 'transparent'
            });
            api.closeFrame({
                name: 'main_login_win'
            });
        },
        do_openWin: function(newsid, newstype, msgType) {
            var that = this;
            //客服工单
            if (newstype == 'customerservice') {
                ns.openWin('home_task_con_frm', '详情', {
                    id: newsid
                });
            }
            //品控
            if (newstype == 'qualitycontrol') {
                ns.openWin('qualitycontroldetail_frm', '详情', {
                    id: newsid
                });
            }
            //设备巡检/维保
            if (newstype == 'deviceplan') {
                ns.openWin('equipment_list_frm', '详情', {
                    id: newsid
                });
            }
            //安防巡更
            if (newstype == 'patrolplan') {
                ns.openWin('patrolplan_list_frm_new', '详情', {
                    id: newsid
                });
                // ns.openWin('patrolplan_list_frm', '详情', {
                //     id:newsid
                // });

            }
            //绿化保洁
            if (newstype == 'enventregionplan') {
                ns.openWin('bjlh_list_frm', '详情', {
                    id: newsid
                });
            }
            //审批
            if (newstype == 'approvalcenter') {
                if (msgType == 18 || msgType == 19 || msgType == 20) {
                    ns.openWin('examine_detail_hetong', '详情', {
                        ApprovalID: newsid,
                        Type: msgType
                    });
                } else if (msgType == 21 || msgType == 22 || msgType == 23 || msgType == 24 || msgType == 25 || msgType == 26 || msgType == 27 || msgType == 28 || msgType == 29 || msgType == 30) {
                    ns.openWin('examine_detail_yg_bangong', '审批详情', {
                        ApprovalID: newsid,
                        Type: msgType
                    });
                } else {
                    ns.openWin('examine_detail', '详情', {
                        ApprovalID: newsid,
                        Type: msgType
                    });
                }

            }
            //通知公告
            if (newstype == 'wechatmsg') {
                ns.openWin('tongzhixiaoxidetail_frm', '详情', {
                    id: newsid
                });
                api.sendEvent({
                    name: 'isreadtrue',
                    extra: {
                        key1: 'value1'
                    }
                });
            }
            //内部通知
            if (newstype == 'intramsg') {
                ns.openWin('neibutz_detail_frm', '内部通知详情', {
                    id: newsid
                });
            }
        }
    }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    setTimeout(function() {
        app.set_status_bar();
    }, 2000)
    api.addEventListener({
        name: 'isAllNumber'
    }, function(ret, err) {
        app.footers[1].count = ret.value.AllCount;
    });
    api.addEventListener({
        name: 'onlogin'
    }, function(ret, err) {
        app.set_status_bar();
    });
    var delay = 100;
    if (api.systemType != 'ios') {
        delay = 100;
    }
    var body_h = $api.offset($api.dom('body')).h;
    app.open_menu(app.footers[0]);
    api.addEventListener({
        name: 'ajpushnotifyalert'
    }, function(ret, err) {
        app.do_openWin(ret.value.id, ret.value.type, ret.value.msgType);
    });
}
